Python: Why can't I use `super` on a class?

Posted by cool-RR on Stack Overflow See other posts from Stack Overflow or by cool-RR
Published on 2011-01-13T22:49:09Z Indexed on 2011/01/13 22:53 UTC
Read the original article Hit count: 372

Filed under:
|
|

Why can't I use super to get a method of a class's superclass?

Example:

Python 3.1.3
>>> class A(object):
...     def my_method(self): pass
>>> class B(A):
...     def my_method(self): pass
>>> super(B).my_method
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    super(B).my_method
AttributeError: 'super' object has no attribute 'my_method'

(Of course this is a trivial case where I could just do A.my_method, but I needed this for a case of diamond-inheritance.)

According to super's documentation, it seems like what I want should be possible. This is super's documentation: (Emphasis mine)

super() -> same as super(__class__, <first argument>)

super(type) -> unbound super object

super(type, obj) -> bound super object; requires isinstance(obj, type)

super(type, type2) -> bound super object; requires issubclass(type2, type)

[non-relevant examples redacted]

© Stack Overflow or respective owner

Related posts about python

Related posts about class